<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css"
	href="../resources/admin/css/header.css">
<link rel="stylesheet" type="text/css"
	href="../resources/admin/css/criclemenu.css">
<link rel="stylesheet" type="text/css"
	href="../resources/admin/css/add-category.css">
<link rel="stylesheet" type="text/css"
	href="../resources/admin/css/category.css">
</head>

<link rel="stylesheet" type="text/css"
	href="../resources/admin/css/jquery.treeview.css">

<script type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script src="../resources/admin/js/jquery.cookie.js"
	type="text/javascript"></script>
<script src="../resources/admin/js/jquery.treeview.js"
	type="text/javascript"></script>
<script src="../resources/admin/js/demo.js" type="text/javascript"></script>
<body>
	<div style="margin-top: 50px;">Quản Lý Danh Mục</div>
	<div>
		<a href="category.html?categoryId=-1" class="button">Thêm</a>
	</div>

	<div class="left">
		<ul id="red" class="treeview-red">

			<%-- 	<c:forEach var="item" items="${newmodel.childs}">--%>



			<c:forEach var="menuItem" items="${newmodel.childs}">
				<li><a
					href="category.html?categoryId=${menuItem.value.categoryId}"
					rel="${menuItem.value.categoryId}">
						${menuItem.value.categoryName} </a> <c:if
						test="${menuItem.hasChild()}">
						<ul id="${menuItem.value.categoryId}">
							<c:forEach var="item1" items="${menuItem.childs}">
								<li><a
									href="category.html?categoryId=${item1.value.categoryId}">
										${item1.value.categoryName}</a> <c:if test="${item1.hasChild()}">
										<ul>
											<c:forEach var="ii" items="${item1.childs}">
												<li><a
													href="category.html?categoryId=${ii.value.categoryId}">
														${ii.value.categoryName}</a> <c:if test="${ii.hasChild()}">
														<ul>
															<c:forEach var="iii" items="${ii.childs}">
																<li><a
																	href="category.html?categoryId=${iii.value.categoryId}">
																		${iii.value.categoryName} </a> <c:if
																		test="${iii.hasChild()}">
																		<ul>
																			<c:forEach var="iiii" items="${iii.childs}">
																				<li><a
																					href="category.html?categoryId=${iiii.value.categoryId}">
																						${iiii.value.categoryName} </a></li>
																			</c:forEach>
																		</ul>
																	</c:if></li>
															</c:forEach>
														</ul>
													</c:if></li>
											</c:forEach>
										</ul>
									</c:if></li>
							</c:forEach>
						</ul>
					</c:if></li>
			</c:forEach>
			<%-- </li>
			</c:forEach> --%>
		</ul>
	</div>
	<div class="right">
		<c:choose>
			<c:when test="${category.categoryId > 0}">

				<form:form method="POST" action="saveCategory.html">
					<div class="CSSTableGenerator">
						<div>
							<form:label path="categoryId">Mã Danh Mục: </form:label>
							<form:input path="categoryId" value="${category.categoryId}"
								readonly="true" style="margin-left: 200px" />
							<hr width="100%">
						</div>

						<div>
							<form:label path="priority">Bậc: </form:label>
							<form:input path="priority" value="${category.priority}"
								readonly="true" style="margin-left: 280px" />
							<hr width="100%">
						</div>

						<div>
							<form:label path="categoryName">Tên Danh Mục: </form:label>
							<form:input path="categoryName" value="${category.categoryName}"
								style="margin-left: 200px" />
							<hr width="100%">
						</div>
						<div>
							<form:label path="parentId">Danh Mục Cha: </form:label>

							<form:select path="parentId"
								style="margin-left: 200px; width: 150px;">
								<c:choose>
									<c:when test="${categoryParent.categoryId == 0}">
										<form:option value="-1" label="" />

										<c:forEach var="cate" items="${categories}">
											<c:if test="${cate.categoryId != category.categoryId}">
												<form:option value="${cate.categoryId}"
													label="${cate.categoryName }" />

											</c:if>
										</c:forEach>
									</c:when>
									<c:otherwise>
										<form:option value="${categoryParent.categoryId}"
											label="${categoryParent.categoryName}" />

										<c:forEach var="cate" items="${categories}">
											<c:if test="${cate.categoryId != category.categoryId}">
												<form:option value="${cate.categoryId}"
													label="${cate.categoryName }" />

											</c:if>
										</c:forEach>

										<form:option value="-1" label="" />
									</c:otherwise>
								</c:choose>



							</form:select>
							<hr width="100%">
						</div>

						<div>
							<form:label path="tag">Từ Khóa: </form:label>
							<form:input path="tag" value="${category.tag}"
								style="margin-left: 245px" />
							<hr width="100%">
						</div>

						<div>
							<form:label path="status">Trạng Thái: </form:label>
							<form:input path="status" value="${category.status}"
								style="margin-left: 225px" />
							<hr width="100%">
						</div>

						<div>
							<form:label path="description">Mô Tả: </form:label>
							<form:input path="description" value="${category.description}"
								style="margin-left: 255px" />
							<hr width="100%">
						</div>


					</div>

					<input type="submit" value="Lưu" class="button"
						style="margin-top: 30px; margin-left: 150px;" />
					<input type="hidden" name="${_csrf.parameterName}"
						value="${_csrf.token}" />
				</form:form>

				<div style="margin-top: -25px; margin-left: 230px">
					<a href="deleteCategory.html?categoryId=${category.categoryId}"
						class="button">Xóa</a>
				</div>


				<%-- 				<a href="deleteCategory.html?categoryId=${category.categoryId}" style="background-color: #61aedb; color: #fff; width: 100px; height: 40px;">Delete</a>
 --%>
			</c:when>

			<c:otherwise>

				<form:form method="POST" action="addCategory.html">
					<div class="CSSTableGenerator">

						<div>
							<form:label path="categoryName">Tên Danh Mục: </form:label>
							<form:input path="categoryName" value=""
								style="margin-left: 200px" />
							<hr width="100%">
						</div>
						<div>
							<form:label path="parentId">Danh Mục Cha: </form:label>

							<form:select path="parentId"
								style="margin-left: 200px; width: 150px;">
								<c:forEach var="cate" items="${categories}">
									<form:option value="-1" label="" />
									<form:option value="${cate.categoryId}"
										label="${cate.categoryName }" />
								</c:forEach>
							</form:select>
							<hr width="100%">
						</div>

						<div>
							<form:label path="tag">Từ Khóa: </form:label>
							<form:input path="tag" value="" style="margin-left: 245px" />
							<hr width="100%">
						</div>

						<div>
							<form:label path="status">Trạng Thái: </form:label>
							<form:input path="status" value="" style="margin-left: 225px" />
							<hr width="100%">
						</div>

						<div>
							<form:label path="description">Mô Tả: </form:label>
							<form:input path="description" value=""
								style="margin-left: 255px" />
							<hr width="100%">
						</div>


					</div>

					<input type="submit" value="Thêm"
						style="margin-top: 30px; margin-left: 150px; width: 100px; height: 40px; background-color: #61aedb; color: #fff" />
					<input type="hidden" name="${_csrf.parameterName}"
						value="${_csrf.token}" />
				</form:form>

			</c:otherwise>
		</c:choose>
	</div>
</body>
